#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <string.h>

int n = 0;
pthread_rwlock_t mutex;

void * f(void* a)
{
    for (int i=0;i<500000;i++)
    {
        pthread_rwlock_wrlock(&mutex);
        n++;
        pthread_rwlock_unlock(&mutex);
    }
}

int main()
{
    pthread_t t1,t2;
    pthread_rwlock_init(&mutex,NULL);

    pthread_create(&t1,NULL,f,NULL);
    pthread_create(&t2,NULL,f,NULL);

    void* p1;
    void * p2;
    pthread_join(t1,&p1);
    pthread_join(t2,&p2);
    pthread_rwlock_destroy(&mutex);
    printf("%d\n",n);

}